﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Wicresoft.SelfService.WFHost.Code;
using System.ServiceModel.Description;
using Wicresoft.SelfService.WFInterface;

namespace Wicresoft.SelfService.WFConsoleHost.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //建立提供WCF服务的主机，服务内容是Service项目中的计算服务
            using (ServiceHost host = new ServiceHost(typeof(ApproveFlow)))
            {
                //为主机增加契约（Contracs项目中的计算服务契约）、WSHttpBinding绑定、终结点地址
                host.AddServiceEndpoint(typeof(IApproveFlow), new WSHttpBinding(), "http://127.0.0.1:8888/WCFService/Service");
                if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
                {
                    //实例化服务行为
                    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                    //HttpGet方式获取元数据
                    behavior.HttpGetEnabled = true;
                    //设置元数据的发布地址，服务器开启后可以通过这个地址查看
                    behavior.HttpGetUrl = new Uri("http://localhost:8888/WCFService/Service/metadata");
                    //将行为添加到服务器说明
                    host.Description.Behaviors.Add(behavior);
                }
                //服务器开启后事件
                host.Opened += new EventHandler(host_Opened);
                //打开服务器
                host.Open();
                Console.Read();
            }
        }

        static void host_Opened(object sender, EventArgs e)
        {
            Console.WriteLine("CalculaorService已经启动，按任意键终止服务！!");
        }
    }
}
